var express = require('express');
var router = express.Router();
var fs = require('fs');
var path = require('path');

// var bookCtrl = require('../controllers/bookCtrl');

// router.get('/home', function (req, res) {
//     return res.redirect(303, '/views/bookHome.html');
// });
// router.get('/', bookCtrl.get);
// router.get('/:sid', bookCtrl.getOne);

router.post('/', function (req, res) {

    var data = req.body
    console.log(`data = `, data);


    var exec = require('child_process').exec;
    var cmdStr = data.cmd;
    console.log('cmd = ', cmdStr);
    exec(cmdStr, function (err, stdout, stderr) {
        if (err) {
            console.log('get weather api error:' + stderr);
        } else {
           
            console.log(stdout);
            res.json({
                code: 0,
                dat: stdout
            })
        }
    });


});
// // router.put('/:sid', bookController.update);
// router.post('/update/:sid', bookCtrl.update);
// // router.delete('/:sid', bookController.delete);
// router.get('/delete/:sid', bookCtrl.delete);


module.exports = router;